<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Models\Advantage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class AdvantageController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $advantages = Advantage::all();
        return $advantages;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return Response
     */
    public function store(Request $request, Advantage $advantage)
    {
        $request->validate([
            'title' => ['required'],
            'content' => ['required']
        ]);
        $advantage->create($request->input());
        return $this->message('添加成功');
    }

    /**
     * Display the specified resource.
     *
     * @param Advantage $advantage
     * @return Response
     */
    public function show(Advantage $advantage)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param Advantage $advantage
     * @return Response
     */
    public function edit(Advantage $advantage)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param Request $request
     * @param Advantage $advantage
     * @return Response
     */
    public function update(Request $request, Advantage $advantage)
    {
        $request->validate([
            'title' => ['required'],
            'content' => ['required']
        ]);
        $advantage->update($request->input());
        $advantage->save();
        return $this->message('修改成功');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param Advantage $advantage
     * @return Response
     */
    public function destroy(Advantage $advantage)
    {
        $advantage->delete();
        return $this->message('删除成功');
    }
}
